// #include"../include/stringDataModel.h"
#include "stringDataModel.h"

StringDataModel::StringDataModel(){
    initCommandMap();
}
StringDataModel::~StringDataModel(){

}

void StringDataModel::del(const std::string&){
    stringDataModel = "";
}
std::string StringDataModel::executeCommand(const std::string& command, std::istringstream& iss)
{
    if(commandMap.count(command)) {
        // std::cout << "Executing command: " << command << " ";
        return commandMap[command](iss);
    }
    return "error String " + command + " not found";
}

void StringDataModel::initCommandMap()
{
    commandMap["set"] = [this] (std::istringstream& iss) -> std::string {
        std::string value;
        iss >> value;
        stringDataModel = value;
        return "OK";
    };
    commandMap["get"] = [this] (std::istringstream& iss) -> std::string {
        return stringDataModel;
    };
    commandMap["del"] = [this] (std::istringstream& iss) -> std::string {
        stringDataModel = "";
        return "OK";
    };
}
